<template>
  <div class="luotong">
    <div class="content_title" v-if="!inline">
      <span @click="showDialogTech" style="cursor:pointer">
        <span class="content_text">络筒</span>
        <img class="content_img" src="../assets/img/resource/icon/luotong.png" alt="" srcset="" />
      </span>
    </div>
    <div class="luotong_body">
      <div class="luotong_row1"></div>
      <div class="luotong_row2">
        <div class="item" v-for="(item, index) in luoTongData.luotongRow1Data" :key="index + '1'">
          <div v-if="index == 3 || index == 11">
            <div class="dongli" @click="clickHandleDl('luotong2_' + index)">
              <img src="../assets/img/dongli.svg" alt="" srcset="" />
            </div>
          </div>
          <div v-if="index == 6 && !inline">
            <div class="wendu">
              <img src="../assets/img/wendu.svg" alt="" srcset="" />
            </div>
          </div>
          <div v-if="Number(item.devSn) % 2 == 0" @click="clickHandle(item)">
            <luotong_l :data="item" :inline="inline"></luotong_l>
          </div>
          <div v-if="Number(item.devSn) % 2 != 0" @click="clickHandle(item)">
            <luotong_r :data="item" :inline="inline"></luotong_r>
          </div>
        </div>
      </div>
      <div class="luotong_row3">
        <div class="item1" v-for="(item, index) in luoTongData.luotongRow2Data" :key="index + '2'">
          <!-- 待修改 -->
          <div v-if="index <= 9">
            <div v-if="index == 1 || index == 10">
              <div class="dongli" @click="clickHandleDl('luotong3_' + index)">
                <img src="../assets/img/dongli.svg" alt="" srcset="" />
              </div>
            </div>
            <div v-if="index == 0 && !inline">
              <div class="wendu1">
                <img src="../assets/img/wendu.svg" alt="" srcset="" />
              </div>
            </div>
            <div v-if="Number(item.devSn) % 2 == 0" @click="clickHandle(item)">
              <luotong_l :data="item" :inline="inline"></luotong_l>
            </div>
            <div v-if="Number(item.devSn) % 2 != 0" @click="clickHandle(item)">
              <luotong_r :data="item" :inline="inline"></luotong_r>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 络筒弹窗控件 -->
    <luoTongDialog ref="luoTongDialog"></luoTongDialog>
    <!-- 动力柜弹窗控件 -->
    <dongliDialog ref="dongliDialog"></dongliDialog>
    <!-- 络筒工艺详情 -->
    <luotong-dialog-tech v-if="techShow" ref="luotongDialogTech"></luotong-dialog-tech>
  </div>
</template>

<script>
import luoTongDialog from "../views/qcs/components/dialog/dialog_luotong/index";
import dongliDialog from "../views/qcs/components/dialog/dialog_dongli/index";
import luotong_l from "../views/qcs/components/luotong_l";
import luotong_r from "../views/qcs/components/luotong_r";
import COMMON from "../utils/common";
import dongLiMenu from "@/assets/data/dongli.json";
import dongliItem from "@/assets/data/dongliItem.json";
export default {
  name: "LuoTong",
  props: {
    msg: String,
    // 是否嵌套在弹窗内
    inline: {
      type: Boolean,
      default: false
    }
  },
  components: {
    luoTongDialog,
    luotong_l,
    luotong_r,
    dongliDialog
  },
  data() {
    return {
      luoTongData: {
        luotongRow1Data: [],
        luotongRow2Data: []
      },
      dongLiMenu: {},
      dongLiItem: {},
      techShow: false
    };
  },
  // 组件相互调用 需在beforeCreate注册
  beforeCreate: function() {
    this.$options.components.luotongDialogTech = require("../views/qcs/components/dialogBig/dialog_luotong_tech/index").default;
  },
  created() {
    this.dongLiMenu = dongLiMenu;
    this.dongLiItem = dongliItem;
  },
  computed: {
    luoTongGroupState() {
      return this.$store.state.luoTongGroupState;
    }
  },
  watch: {
    luoTongGroupState: {
      immediate: true,
      handler(val) {
        // console.log("luoTongval.data",val.data)
        this.luoTongData.luotongRow1Data = COMMON.devSnFilter(val.data, 1, 14);
        this.luoTongData.luotongRow2Data = COMMON.devSnFilter(val.data, 15, val.data.length);
      }
    }
  },
  methods: {
    closeHandle(type) {
      // 若细砂组件在1.5级弹窗内，当关闭二级弹窗时，需要打开1.5级的轮询
      if (this.inline) {
        // 关闭二级轮询
        if (type == "secLuoTongTimer") {
          this.$EventBus.$emit("clearTypeInterval", "secLuoTongTimer");
          this.$EventBus.$emit("clearTypeInterval", "secLuoTongTimerA");
        } else {
          this.$EventBus.$emit("clearTypeInterval", type);
        }
        this.$parent.$parent.getTableData();
      } else {
        this.$parent.closeParentHandle();
      }
    },
    clickHandle(item) {
      // 若细砂组件在1.5级弹窗内，当打开二级弹窗时，需要关闭1.5级的轮询
      if (this.inline) {
        this.$EventBus.$emit("getInfoByDevSn", "LUOTONG", item.devSn);
        this.$EventBus.$emit("inlineDialog", "close");
      } else {
        this.$parent.getInfoByDevSn("LUOTONG", item.devSn);
      }
      this.$refs.luoTongDialog.showDialog(item);
    },
    clickHandleDl(item) {
      var getInfoQuary = this.dongLiMenu[item];
      var dialogData = this.dongLiItem[item];
      // 若细砂组件在1.5级弹窗内，当打开二级弹窗时，需要关闭1.5级的轮询
      if (this.inline) {
        this.$EventBus.$emit("getInfoByDevSn", "DONGLI", getInfoQuary);
        this.$EventBus.$emit("inlineDialog", "close");
      } else {
        this.$parent.getInfoByDevSn("DONGLI", getInfoQuary);
      }
      this.$refs.dongliDialog.showDialog(dialogData);
    },
    showDialogTech() {
      this.techShow = true;
      this.$nextTick(() => {
        setTimeout(() => {
          // 初始化请求
          // 1.5级轮询
          this.$parent.openInlineDialog("LUOTONG", { start: 1, end: 24 }, true);
          this.$refs.luotongDialogTech.showDialog();
        });
      });
    },
    closeDialogTech() {
      this.techShow = false;
      this.$parent.closeParentHandle();
    }
  }
};
</script>

<style scoped></style>
